#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    picID = 2;
    QPixmap pix("D:\\QT\\QtProject\\3_objectTimer\\1.jpg");//标签显示图片
    ui->label->setPixmap(pix);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_startButton_clicked()
{
    //开启定时器，返回定时器编号
    myTimerId = this->startTimer(TIMEOUT);//开启计时

}
void Widget::on_pushButton_2_clicked()
{
   this->killTimer(myTimerId);//关闭定时器
}


void Widget::timerEvent(QTimerEvent *event)//定时器触发函数
{
    if(event->timerId()!=myTimerId)//如果定时器编号不一致
        return;
    QString path("D:\\QT\\QtProject\\3_objectTimer\\");
    path += QString::number(picID+1);
    path += ".jpg";
    QPixmap pix(path);//标签显示图片
    ui->label->setPixmap(pix);

    picID=(++picID)%3;
}



